package command;

import java.net.InetAddress;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import com.sun.xml.internal.bind.v2.runtime.RuntimeUtil.ToStringAdapter;

import base.*;


public class GetFileCommand extends Command{

	InetAddress ip;
	private int port;
	
	private String key;
	private String sresponse;
	
	
	public boolean run(){
		DataTracker d = new DataTracker();
		d.createEm();
		
		List<Peer> peers = d.findPeerByKey(this.key);
		sresponse = "peers " + this.key + " [";
		for(Peer p:peers){
			sresponse += "" + p.getPeerIP().getHostAddress() + ":" + p.getPeerPortNumber();
		}
		sresponse += "]";
	return true;
	}

	/**
	    * Sets the ip for this instance.
	    *
	    * @param ip The ip.
	    */
	   public void setIp(InetAddress ip)
	   {
	      this.ip = ip;
	   }

	   /**
	    * Sets the port for this instance.
	    *
	    * @param port The port.
	    */
	   public void setPort(int port)
	   {
	      this.port = port;
	   }

	    /**
	    * Sets the key for this instance.
	    *
	    * @param key The key.
	    */

	   public void setKey(String key){
		this.key = key;
	   }
	

	   public String getSresponse() 
	   {
		   return sresponse;
	   }
	   
	   public String toString(){
		  return  "key: " + this.key ;
	   }
}
